home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / PROT018S.ZIP / ANSI_DRV.PAS next >
Pascal/Delphi Source File  |  1992-12-18  |  8KB  |  298 lines

  1. {                                                                         }
  2. {  Copywrite 1993 Mark Dignam - Omen Computer Services - Perth Omen BBS.  }
  3. {  This program ,including the source code MAY not be modified, changed   }
  4. {  or altered in any way without written permission of the author.        }
  5. {                                                                         }
  6. {                                                                         }
  7. { Ansi Driver for Comms routines                                          }
  8.  
  9. unit Ansi_Drv;
  10.  
  11. interface
  12.  
  13. Uses Crt,dos;
  14.  
  15. procedure Ansi_Write(ch : char);
  16.  
  17. Implementation
  18.  
  19. Var
  20.     Escape,Saved_X,
  21.     Saved_Y               : Byte;
  22.     Control_Code          : String;
  23.  
  24. function GetNumber(var Line:string):integer;
  25.  
  26.    var
  27.      i,j,k         : integer;
  28.      temp0,temp1   : String;
  29.  
  30.   Begin
  31.        temp0 := line;
  32.        val(temp0,i,j);
  33.       if j = 0 then temp0 :=''
  34.        else
  35.       begin
  36.          temp1:= copy(temp0,1,j-1);
  37.          delete(temp0,1,j);
  38.          val(temp1,i,j);
  39.       end;
  40.     line := temp0;
  41.     GetNumber := i;
  42.   end;
  43.  
  44.  procedure loseit;
  45.     begin
  46.       escape := 0;
  47.       control_code := '';
  48.     end;
  49.  
  50.  procedure Ansi_Cursor_move;
  51.  
  52.      var
  53.       x,y       : integer;
  54.  
  55.     begin
  56.      y := GetNumber(control_code);
  57.      if y = 0 then y := 1;
  58.      x := GetNumber(control_code);
  59.      if x = 0 then x := 1;
  60.      if y > 25 then y := 25;
  61.      if x > 80 then x := 80;
  62.      gotoxy(x,y);
  63.     loseit;
  64.     end;
  65.  
  66. procedure Ansi_Cursor_up;
  67.  
  68.  Var
  69.    y,new_y,offset          : integer;
  70.  
  71.    Begin
  72.      Offset := getnumber(control_code);
  73.         if Offset = 0 then offset := 1;
  74.       y := wherey;
  75.       if (y - Offset) < 1 then
  76.              New_y := 1
  77.           else
  78.              New_y := y - offset;
  79.        gotoxy(wherex,new_y);
  80.   loseit;
  81.   end;
  82.  
  83. procedure Ansi_Cursor_Down;
  84.  
  85.  Var
  86.    y,new_y,offset          : integer;
  87.  
  88.    Begin
  89.      Offset := getnumber(control_code);
  90.         if Offset = 0 then offset := 1;
  91.       y := wherey;
  92.       if (y + Offset) > 25 then
  93.              New_y := 25
  94.           else
  95.              New_y := y + offset;
  96.        gotoxy(wherex,new_y);
  97.   loseit;
  98.   end;
  99.  
  100. procedure Ansi_Cursor_Left;
  101.  
  102.  Var
  103.    x,new_x,offset          : integer;
  104.  
  105.    Begin
  106.      Offset := getnumber(control_code);
  107.         if Offset = 0 then offset := 1;
  108.       x := wherex;
  109.       if (x - Offset) < 1 then
  110.              New_x := 1
  111.           else
  112.              New_x := x - offset;
  113.        gotoxy(new_x,wherey);
  114.   loseit;
  115.   end;
  116.  
  117. procedure Ansi_Cursor_Right;
  118.  
  119.  Var
  120.    x,new_x,offset          : integer;
  121.  
  122.    Begin
  123.      Offset := getnumber(control_code);
  124.         if Offset = 0 then offset := 1;
  125.       x := wherex;
  126.       if (x + Offset) > 80 then
  127.              New_x := 1
  128.           else
  129.              New_x := x + offset;
  130.        gotoxy(New_x,wherey);
  131.   loseit;
  132.   end;
  133.  
  134.  procedure Ansi_Clear_Screen;
  135.  
  136.    begin                         {   0J = cusor to Eos           }
  137.      Clrscr;                      {  1j start to cursor           }
  138.      loseit;                       { 2j entie screen/cursor no-move}
  139.    end;
  140.  
  141.  procedure Ansi_Clear_EoLine;
  142.  
  143.    begin
  144.      clreol;
  145.      loseit;
  146.    end;
  147.  
  148.  
  149.  procedure Reverse_Video;
  150.  
  151.  var
  152.       tempAttr,tblink,tempAttrlo,tempAttrhi : Byte;
  153.  
  154.  begin
  155.             LowVideo;
  156.             TempAttrlo := (TextAttr and $7);
  157.             tempAttrHi := (textAttr and $70);
  158.             tblink     := (textattr and $80);
  159.             tempattrlo := tempattrlo * 16;
  160.             tempattrhi := tempattrhi div 16;
  161.             TextAttr   := TempAttrhi+TempAttrLo+TBlink;
  162.   end;
  163.  
  164.  
  165.  procedure Ansi_Set_Colors;
  166.  
  167.  var
  168.     temp0,Color_Code   : integer;
  169.  
  170.     begin
  171.         if length(control_code) = 0 then control_code :='0';
  172.            while (length(control_code) > 0) do
  173.            begin
  174.             Color_code := getNumber(control_code);
  175.                 case Color_code of
  176.                    0          :  begin
  177.                                    LowVideo;
  178.                                    TextColor(LightGray);
  179.                                    TextBackground(Black);
  180.                                  end;
  181.                    1          : HighVideo;
  182.                    5          : TextAttr := (TextAttr or $80);
  183.                    7          : Reverse_Video;
  184.                    30         : textAttr := (TextAttr And $F8) + black;
  185.                    31         : textattr := (TextAttr And $f8) + red;
  186.                    32         : textattr := (TextAttr And $f8) + green;
  187.                    33         : textattr := (TextAttr And $f8) + brown;
  188.                    34         : textattr := (TextAttr And $f8) + blue;
  189.                    35         : textattr := (TextAttr And $f8) + magenta;
  190.                    36         : textattr := (TextAttr And $f8) + cyan;
  191.                    37         : textattr := (TextAttr And $f8) + Lightgray;
  192.                    40         : textbackground(black);
  193.                    41         : textbackground(red);
  194.                    42         : textbackground(green);
  195.                    43         : textbackground(yellow);
  196.                    44         : textbackground(blue);
  197.                    45         : textbackground(magenta);
  198.                    46         : textbackground(cyan);
  199.                    47         : textbackground(white);
  200.                  end;
  201.              end;
  202.        loseit;
  203.   end;
  204.  
  205.  
  206.  procedure Ansi_Save_Cur_pos;
  207.  
  208.     Begin
  209.       Saved_X := WhereX;
  210.       Saved_Y := WhereY;
  211.       loseit;
  212.     end;
  213.  
  214.  
  215.  procedure Ansi_Restore_cur_pos;
  216.  
  217.     Begin
  218.       GotoXY(Saved_X,Saved_Y);
  219.       loseit;
  220.     end;
  221.  
  222.  
  223.  procedure Ansi_check_code( ch : char);
  224.  
  225.    begin
  226.        case ch of
  227.             '0'..'9',';'     : control_code := control_code + ch;
  228.             'H','f'          : Ansi_Cursor_Move;
  229.             'A'              : Ansi_Cursor_up;
  230.             'B'              : Ansi_Cursor_Down;
  231.             'C'              : Ansi_Cursor_Right;
  232.             'D'              : Ansi_Cursor_Left;
  233.             'J'              : Ansi_Clear_Screen;
  234.             'K'              : Ansi_Clear_EoLine;
  235.             'm'              : Ansi_Set_Colors;
  236.             's'              : Ansi_Save_Cur_Pos;
  237.             'u'              : Ansi_Restore_Cur_pos;
  238.         else
  239.           loseit;
  240.         end;
  241.    end;
  242.  
  243.  
  244. procedure Ansi_Write(ch : char);
  245.  
  246. Var
  247.   temp0      : Integer;
  248.  
  249. begin
  250.        if escape > 0 then
  251.           begin
  252.               case Escape of
  253.                 1    : begin
  254.                          if ch = '[' then
  255.                             begin
  256.                               escape := 2;
  257.                               Control_Code := '';
  258.                             end
  259.                          else
  260.                              escape := 0;
  261.                        end;
  262.                 2    : Ansi_Check_code(ch);
  263.               else
  264.                 begin
  265.                    escape := 0;
  266.                    control_code := '';
  267.                 end;
  268.               end;
  269.           end
  270.        else
  271.          Begin
  272.           Case Ch of
  273.              #27       : Escape := 1;
  274.              #9        : Begin
  275.                             temp0:= wherex;
  276.                             temp0 := temp0 div 8;
  277.                             temp0 := temp0 + 1;
  278.                             temp0 := temp0 * 8;
  279.                             gotoxy(temp0,wherey);
  280.                          end;
  281.              #12       : ClrScr;
  282.           else
  283.                  begin
  284.                     if ((wherex = 80) and (wherey = 25)) then
  285.                       begin
  286.                         windmax := (80 + (24*256));
  287.                         write(ch);
  288.                         windmax := (79 + (24*256));
  289.                       end
  290.                     else
  291.                       write(ch);
  292.                     escape := 0;
  293.                  end;
  294.            end;
  295.          end;
  296.   End;
  297. end.
  298.